
$(function() {
  $("form").validate({
    errorElement: "span",
    success: function($label) {
      $label.addClass("valid").text("OK!");
    },
    onfocusout: function (element) {
      $(element).valid();
    }
  });
  $(document).on("ajax:success", 'a[data-remote],input[data-remote]', function (e, data) {
    var $this = $(this);
    if (data.success) {
      var text = data.message || "操作成功";
      noty({type: "success", text: text});
      var redirect = $this.attr("data-redirect");
      if (redirect) {
        setTimeout(function() {
          window.location.href = redirect;
        }, 2000);
      }
    } else {
      noty({type: "error", text: data.message});
    }
  });
});
